package user

import (
	"context"
	"fmt"

	"zerodemo/user-api/internal/svc"
	"zerodemo/user-api/internal/types"
	"zerodemo/user-rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
	return &UserInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserInfoLogic) UserInfo(req *types.UserInfoReq) (resp *types.UserInfoResp, err error) {
	// todo: add your logic here and delete this line
	fmt.Println("logic……")
	userResp, err := l.svcCtx.UserRpcClient.GetUserInfo(l.ctx, &pb.GetUserInfoReq{
		Id: req.UserId,
	})
	if err != nil {
		return nil, err
	}
	return &types.UserInfoResp{
		UserId:   userResp.Id,
		Nickname: userResp.Nickname,
	}, nil
	// copier.Copy
	// logx.Info("日志打印")

	// userInfo, err := l.svcCtx.UserModel.FindOne(l.ctx, req.UserId)
	// if err != nil && err != model.ErrNotFound {
	// 	return nil, errors.New("数据库查询失败")
	// }
	// if userInfo == nil {
	// 	return nil, errors.New("用户不存在")
	// }

	// return &types.UserInfoResp{
	// 	UserId:   userInfo.Id,
	// 	Nickname: userInfo.Nickname,
	// }, nil
}
